#pragma once

#include <QColor>
#include <QWidget>

class HistoryModel;
class QStylePainter;

class ChartView : public QWidget
{
	Q_OBJECT
public:
	ChartView(HistoryModel* model,QWidget* par); 
	void refreshChart();
	void paintEvent(QPaintEvent* eve);
	void resizeEvent(QResizeEvent* eve);

	void setValuss(const QList<int>& pts,int begTime);

	void pushPoint(int val);
	void reset();
	void setStartUpTime(time_t t) {
		m_StartUpTime = t;
	}
private slots:
	void setMode(int mode) {
		m_Mode = mode;
	}


private:
	void drawTitle(QStylePainter* painter = NULL);
	void drawCoord(QStylePainter* painter = NULL);
	void drawPoints(QStylePainter* painter = NULL);
	void calcCoords();
	void calcSpan();
	bool calcHigh();
	void transFormCoords(int mode);
private:
	const static QColor m_GrayColor;
	const static QColor m_BrightColor;
	const static QColor m_LineColor;
	const static QColor m_CoordColor;
	const static QColor m_SepColor;

	int m_VertHigh;
	HistoryModel* m_Model;
	//int m_HorBegin,m_HorEnd;
	int m_Mode;
	QRectF m_Rect;
	QRect m_TitleRect;
	QRectF m_CoordRect;

	float m_XSpan;
	int m_YSpan;
	float m_XMicSpan;
	float m_YReadSpan;

	QList<int> m_Values;
	int m_BegTime;
	time_t m_StartUpTime;
	QList<QPointF> m_Points;
};